package com.wust.mode;

import com.wust.database.DatabaseFactory;
import com.wust.util.ConstDefine;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class ModeDao {
	private Context context;
	public ModeDao(Context context)
	{
		this.context=context;
	}
	public void insertMode()
	{
		DatabaseFactory database=new DatabaseFactory(context,ConstDefine.DatabaseFactoryUtil.DATABASE_NAME);
		SQLiteDatabase db=database.getWritableDatabase();
		db.execSQL("INSERT INTO da_mode VALUES (1, 50.6, 3.27, 32.8, 34.3, '男', 0)");
		db.execSQL("INSERT INTO `da_mode` VALUES ('2', '56.5', '4.97', '37.9', '38.1', '男', '1')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('3', '59.6', '5.95', '40', '39.7', '男', '2')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('4', '62.3', '6.73', '41.3', '41', '男', '3')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('5', '64.6', '7.32', '42.3', '42', '男', '4')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('6', '65.9', '7.7', '42.9', '42.9', '男', '5')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('7', '68.1', '8.22', '43.8', '43.9', '男', '6')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('8', '70.6', '8.71', '44.7', '44.9', '男', '8')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('9', '72.9', '9.14', '45.4', '45.7', '男', '10')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('10', '75.6', '9.66', '46.1', '46.3', '男', '12')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('11', '50', '3.17', '32.6', '33.7', '女', '0')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('12', '55.5', '4.64', '36.9', '37.3', '女', '1')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('13', '58.4', '5.49', '38.9', '38.7', '女', '2')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('14', '60.9', '6.23', '40.3', '40', '女', '3')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('15', '62.9', '6.69', '41.1', '41', '女', '4')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('16', '64.5', '7.19', '41.9', '41.9', '女', '5')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('17', '66.7', '7.62', '42.7', '42.8', '女', '6')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('18', '69.1', '8.14', '43.4', '43.7', '女', '8')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('19', '71.4', '8.57', '44.2', '44.5', '女', '10')");
		db.execSQL("INSERT INTO `da_mode` VALUES ('20', '74.1', '9.04', '45', '45.2', '女', '12')");
		db.close();
	}
	public Mode getModeInfo(String sex,String age)
	{
		Mode mode=new Mode();
		DatabaseFactory database=new DatabaseFactory(context,ConstDefine.DatabaseFactoryUtil.DATABASE_NAME);
		SQLiteDatabase db=database.getReadableDatabase();
		Cursor cursor=db.query(ConstDefine.DatabaseFactoryUtil.MODE_TABLE, null, "mode_sex=? and mode_age=?", new String[]{sex,age}, null, null, null);
		while(cursor.moveToNext())
		{
			mode.setMode_id(cursor.getInt(cursor.getColumnIndex("mode_id")));
			mode.setMode_height(cursor.getDouble(cursor.getColumnIndex("mode_height")));
			mode.setMode_width(cursor.getDouble(cursor.getColumnIndex("mode_width")));
			mode.setMode_bust(cursor.getDouble(cursor.getColumnIndex("mode_bust")));
			mode.setMode_headwidth(cursor.getDouble(cursor.getColumnIndex("mode_headwidth")));
			mode.setMode_sex(cursor.getString(cursor.getColumnIndex("mode_sex")));
			mode.setMode_age(cursor.getInt(cursor.getColumnIndex("mode_age")));
		}
		db.close();
		return mode;
	}
}
